package cn.tedu._07springaop.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class LogAspect {

    @Before(value = "execution(public int cn.tedu._07springaop.aop.CalculatorImpl.*(..))")
    public void beforeMethod(JoinPoint joinPoint){
        String name = joinPoint.getSignature().getName();
        String args = Arrays.toString(joinPoint.getArgs());
        System.out.println(name+"方法开始，参数为"+args);
    }

    @AfterReturning(value = "execution(public int cn.tedu._07springaop" +
            ".aop.CalculatorImpl.*(..))",returning = "r")
    public void AfterReturningMethod(JoinPoint joinPoint, Object r){
        String name = joinPoint.getSignature().getName();
        System.out.println(name+"方法执行结束，结果为"+r);
    }

    @After(value = "execution(public int cn.tedu._07springaop" +
            ".aop.CalculatorImpl.*(..))")
    public void afterMethod(JoinPoint joinPoint){
        String name = joinPoint.getSignature().getName();
        System.out.println(name+"方法彻底指定结束并释放资源");

    }
}
